/**
 * 
 */
package tp.pr5.gui;

import java.awt.FlowLayout;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JPanel;

import tp.pr5.Constants;
import tp.pr5.Direction;
import tp.pr5.NavigationObserver;
import tp.pr5.PlaceInfo;
import tp.pr5.RobotEngineObserver;
import tp.pr5.items.InventoryObserver;
import tp.pr5.items.Item;

/**
 * @author usuario_local
 *
 */
public class InfoPanel extends JPanel implements RobotEngineObserver, NavigationObserver, InventoryObserver {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel label;
	/**
	 * 
	 */
	public InfoPanel() 
	{
		this.label = new JLabel();
		this.setLayout(new FlowLayout());
		this.add(this.label);
	}

	@Override
	public void inventoryChange(List<Item> inventory) {
		this.label.setText(Constants.MESSAGE_SAYS + Constants.MESSAGE_CHANGE);		
	}

	@Override
	public void inventoryScanned(String inventoryDescription) {}

	@Override
	public void itemScanned(String description) {}

	@Override
	public void itemEmpty(String itemName) {
		this.label.setText(Constants.MESSAGE_EMPTY + " " + itemName);
	}

	@Override
	public void headingChanged(Direction newHeading) {
		this.label.setText(Constants.MESSAGE_HEADING + newHeading);		
	}

	@Override
	public void initNavigationModule(PlaceInfo initialPlace, Direction heading) {}

	@Override
	public void robotArrivesAtPlace(Direction heading, PlaceInfo place) {
		this.label.setText(Constants.MESSAGE_SAYS + Constants.MESSAGE_ARRIVED + place.getName());
	}

	@Override
	public void placeScanned(PlaceInfo placeDescription) {}

	@Override
	public void placeHasChanged(PlaceInfo placeDescription) {}

	@Override
	public void raiseError(String msg) {
		this.label.setText(msg);
	}

	@Override
	public void communicationHelp(String help) {}

	@Override
	public void engineOff(boolean atShip) {
		if (atShip)
			this.label.setText(Constants.MESSAGE_SAYS + Constants.MESSAGE_FIN_SPACESHIP);
		else
			this.label.setText(Constants.MESSAGE_SAYS + Constants.MESSAGE_DIE);		
	}

	@Override
	public void communicationCompleted() {
		this.label.setText(Constants.MESSAGE_SAYS + Constants.MESSAGE_FIN_QUIT);
	}

	@Override
	public void robotUpdate(int fuel, int recycledMaterial) {
		this.label.setText(Constants.MESSAGE_UPDATE + "(" + fuel + ", " + recycledMaterial + ")");
		
	}

	@Override
	public void robotSays(String message) {
		this.label.setText(message);		
	}

}
